//
//  Fish_WorryListViewController.swift
//  WoodenFishApp
//
//  Created by mac on 2023/10/26.
//  Copyright © 2023 Fish_. All rights reserved.
//

import UIKit

class Fish_WorryListViewController: BasicViewController {
    
    
    let rightB = UIButton.initV(img: "Blocklist")
    var dataSource:[InfoUtil.room]? = []
    
    private lazy var table: UITableView = {
        let view = UITableView(frame: .zero, style: .plain)
        view.separatorStyle = .none
        view.backgroundColor = .clear
        view.delegate = self
        view.dataSource = self
        view.showsVerticalScrollIndicator = false
        view.register(WorryCell.self, forCellReuseIdentifier: "cell")
        view.rowHeight = UITableView.automaticDimension
        return view
    }()
    
    override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)
        self.getData()
    }
    
    
    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view.
        self.setRightItem(rightB)
        rightB.addAct {
            let vc = Fish_WorryPublishViewController()
            self.navigationController?.pushViewController(vc, animated: true)
        }
        view.subviews {
            table
        }
        table.fillContainer()
    }
    
    func getData() -> Void {
//        Toast_View_Tool.show()
//        RT.getRoomList { list in
//            self.dataSource?.removeAll()
//            for item in list.lists{
//                if item.info3 == "0" && item.info0 == self.selectType{
//                    self.dataSource?.append(item)
//                }
//            }
//            Toast_View_Tool.dismiss()
//            self.cardListView.reloadData()
//        }
    }
    
}
    
extension Fish_WorryListViewController:UITableViewDelegate,UITableViewDataSource{
    
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return dataSource?.count ?? 0
    }
    
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath) as! WorryCell
        return cell
    }
    
}


class WorryCell: UITableViewCell {
    
    let headImg = UIImageView.initImgView(img: "avarB")
    let moreB = UIButton.initV(img: "icon_more")
    private var nameL = UILabel.initV(.setTypeFace(16.Fit,type: .system), text: "", textColor:titleColor)
    private var timeL = UILabel.initV(.setTypeFace(14,type: .system), text: "", textColor:.color(hexString: "#666666",alpha: 0.6))
    private var cL = UILabel.initV(.setTypeFace(16,type: .system), text: "", textColor:titleColor)
    
    var model:InfoUtil.commentDta?{
        didSet{
            self.nameL.text = self.model?.name
            self.cL.text = self.model?.content
            if let url = URL(string: self.model?.headImg ?? "") {
                self.headImg.kf.setImage(with: url,placeholder: UIImage.init(named: "avarB"))
            }
            self.timeL.text = self.model?.time
            self.moreB.isHidden = self.model?.id == USEINFOMODEL.id
        }
    }
    
    override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        backgroundColor = .clear
        selectionStyle = .none
        
        contentView.subviews {
            headImg
            moreB
            nameL
            timeL
            cL
        }
        headImg.left(15.Fit).top(5.Fit).size(50.Fit)
        headImg.setAllCorners(corner: 25.Fit)
        
        moreB.size(25.Fit).right(12.Fit)
        moreB.Top == headImg.Top + 10.Fit
        moreB.addAct {
            let view = Report_View()
            view.person = true
            view.reportBlock = { content in
                Toast_View_Tool.show(type: .success,text: "Success!")
            }
            let page = Pop_Up_Custom_View(config: PopUpViewConfig(view: view, size: CGSize(width: screenWidth-30.Fit, height: 415.Fit)))
            page.isCloseFromClean = false
            page.animatedPop()
        }
            
        nameL.height(20.Fit)
        nameL.Leading == headImg.Trailing + 10.Fit
        nameL.CenterY == headImg.CenterY
        nameL.Trailing == moreB.Leading - 10.Fit
        
        cL.bottom(35.Fit).right(25.Fit)
        cL.Top == nameL.Bottom + 10.Fit
        cL.Leading == headImg.Trailing + 10.Fit
        cL.numberOfLines = 0
        
        timeL.height(15.Fit).bottom(10.Fit)
        timeL.Leading == nameL.Leading
        timeL.Trailing == moreB.Leading - 10.Fit

    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }

}
